using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using LHS.Core.TableInfo;

namespace LHS.Win.Report
{
    public partial class rptToaThuoc : DevExpress.XtraReports.UI.XtraReport
    {
        DataSet ds = new DataSet();  
        DataTable dt;
        public rptToaThuoc()
        {
            InitializeComponent();
        }

        private void GroupHeader1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ds = (DataSet)this.DataSource;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dt = ds.Tables[0];
            }
        }

        int count = 0;
        private void lblRecord_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            count++;
            lblRecord.Text = count.ToString() + ")";
        }

        private void xrLabel10_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
              this.lblSex.Text  = dr[InfoPatients.PATSEX].ToString().ToUpper();
            }
        }

        private void lblTenThuoc_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[count - 1];
                string strOriginalMedName = (string.IsNullOrEmpty(dr[InfoMedicine.MIMMEDICINEORIGINALNAME].ToString()) == true) ? string.Empty : " ( " + dr[InfoMedicine.MIMMEDICINEORIGINALNAME].ToString() + ")";
                this.lblTenThuoc.Text = dr[InfoMedicineExport.MEXMEDICINENAME].ToString() + strOriginalMedName ;             
            }
        }

        private void lblQuantity_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[count - 1];
                string strQuantity = (string.IsNullOrEmpty(dr[InfoMedicineExport.MEXTOTALQUANTITY].ToString()) == true || dr[InfoMedicineExport.MEXTOTALQUANTITY].ToString() == "0") ? dr[InfoMedicineExport.MEXQUANTITYPERUNIT].ToString() : dr[InfoMedicineExport.MEXTOTALQUANTITY].ToString();
                this.lblQuantity.Text = " x " + strQuantity + " " + dr[InfoMedicineExport.MEXPRODUCTIONPERUNIT].ToString() ;
            }
        }

        private void GroupFooter1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                if (string.IsNullOrEmpty(dr[InfoClinicalRecord.CLRSKILL].ToString()))
                    e.Cancel = true;
            }
        }

        private void pnlNgayTaiKham_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                if (string.IsNullOrEmpty(dr[InfoClinicalRecord.CLRFOLLOWUPEXAMINATIONDATE].ToString()))
                    e.Cancel = true;
            }
        }

        private void lblLuuy_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[count - 1];
                this.lblLuuy.Text = " ( " +dr[InfoMedicineExport.MEXUSAGEPERDAY].ToString() + ") " + dr[InfoMedicineExport.MEXNOTE].ToString();
            }
        }

        private void panelAdvice_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                if (string.IsNullOrEmpty(dr[InfoClinicalRecord.CLRMEDICALADVICE].ToString()))
                    e.Cancel = true;
            }
        }

        
    }
}
